const getConnection = require('../utils/GetConnection');
const moment = require('moment');

module.exports = {
    async find(){
        let sql = `SELECT access_token AS accessToken,expires_in AS expireTime FROM wechat_access_token`;
        let arr = [];
        return new Promise((resolve, reject) => {
            getConnection(sql, arr, (err, result) => {
                if (err) {
                    reject(err);
                    return;
                }
                resolve(result);
            })
        })
    },
    save(token){
        let sql = `replace into wechat_access_token(id,access_token,expires_in) values(?,?,?)`;
        let arr= [1, token.accessToken, token.expireTime];
        return new Promise((resolve, reject) => {
            getConnection(sql, arr, (err) => {
                if (err) {
                    reject(err);
                }
                resolve();
            })
        })
    }
};